package com.itheima.docker.controller;

import com.itheima.docker.service.DockerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
public class DockerController {

    @Autowired
    private DockerService dockerService;

    @RequestMapping("/")
    public void demo01(HttpServletRequest request, HttpServletResponse response){
        String ip = request.getRemoteAddr();
        System.err.println(ip);
        int number = dockerService.saveAndUpdate(ip);
        response.setHeader("Content-type", "text/html;charset=utf-8");
        try {
            response.getWriter().write("你已访问第"+number+"次");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
